﻿using System.Linq;
using INHollandair.Data;

namespace INHollandair.Core.Repositories
{
    public class BlockedIpRepository
    {
        private readonly PresentatieDBDataContext _context = new PresentatieDBDataContext();

        public IQueryable<Models.BlockedIp> BlockedIpRepo
        {
            get
            {
                return _context.BlockedIps.Select(x => new Models.BlockedIp
                {
                    Id = x.Id,
                    Ip = x.Ip,
                    Created = x.Created
                });
            }
        }

        public void InsertBlockedIp(Models.BlockedIp blockedIp)
        {
            BlockedIp blockedIpToInsert = new BlockedIp
            {
               Id = blockedIp.Id,
               Ip = blockedIp.Ip,
               Created = blockedIp.Created
            };

            _context.BlockedIps.InsertOnSubmit(blockedIpToInsert);
            _context.SubmitChanges();
        }
        public void UpdateBlockedIp(Models.BlockedIp blockedIp)
        {
            BlockedIp blockedIpToUpdate = _context.BlockedIps.First(x => x.Id.Equals(blockedIp.Id));
            blockedIpToUpdate.Id = blockedIp.Id;
            blockedIpToUpdate.Ip = blockedIp.Ip;
            blockedIpToUpdate.Created = blockedIp.Created;

            _context.SubmitChanges();
        }
        public void RemoveBlockedIp(Models.BlockedIp blockedIp)
        {
            BlockedIp blockedIpToRemove = _context.BlockedIps.First(x => x.Id.Equals(blockedIp.Id));
            _context.BlockedIps.DeleteOnSubmit(blockedIpToRemove);
            _context.SubmitChanges();
        }
    }
}
